package gemini.pollux.ui.client.page.content.marketingplan.level.widget;

import gemini.basic.model.Level;

import com.google.gwt.event.shared.GwtEvent;

/**
 * The event collections of internal widget for screen uk 1-21.010-a
 */
public class LevelTableEvent extends GwtEvent<LevelTableHandler> {

	private static Type<LevelTableHandler> TYPE;

	public static Type<LevelTableHandler> getType() {
		if (TYPE == null)
			TYPE = new Type<LevelTableHandler>();
		return TYPE;
	}
	
	private Level level;
	
	public enum EventType {
		EDIT, DELETE, ADD
	}
	
	private EventType eventType;
	
	public LevelTableEvent(){
		this.eventType = EventType.ADD;
	}
	
	public LevelTableEvent(EventType eventType, Level level){
		this.level = level;
		this.eventType = eventType;
	}

	@Override
	protected void dispatch(LevelTableHandler handler) {
		if(eventType.equals(EventType.ADD)){
		handler.onAdd(this);
		} else if(eventType.equals(EventType.DELETE)){
		handler.onDelete(this);
		} else if(eventType.equals(EventType.EDIT)){
		handler.onEdit(this);
		}
	}

	@Override
	public Type<LevelTableHandler> getAssociatedType() {
		return getType();
	}

	public Level getLevel() {
		return level;
	}
}
